Move basic commit API into ostree_sysroot_simple_write_deployment()
authorColin Walters <walters@verbum.org>
Sun, 23 Mar 2014 15:36:09 +0000 (11:36 -0400)
committerColin Walters <walters@verbum.org>
Sun, 23 Mar 2014 15:36:09 +0000 (11:36 -0400)
The admin commands had this shared in tool common, but we want to
encourage external programs to do this as well.

src/libostree/ostree-sysroot.c
src/libostree/ostree-sysroot.h
src/ostree/ot-admin-builtin-deploy.c
src/ostree/ot-admin-builtin-switch.c
src/ostree/ot-admin-builtin-upgrade.c
src/ostree/ot-admin-functions.c
src/ostree/ot-admin-functions.h

index 70186a5808eadd1c6524391d834f873e23ade2b3..0c92f26900ac043a7905dedf06a43f4e185016ad 100644 (file)
@@ -1029,3 +1029,74 @@ ostree_sysroot_origin_new_from_refspec (OstreeSysroot  *sysroot,
   g_key_file_set_string (ret, "origin", "refspec", refspec);
   return ret;
 }
+
+/**
+ * ostree_sysroot_simple_write_deployment:
+ * @sysroot: Sysroot
+ * @osname: (allow-none): OS name
+ * @new_deployment: Prepend this deployment to the list
+ * @merge_deployment: (allow-none): Use this deployment for configuration merge
+ * @flags: Flags controlling behavior
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Prepend @new_deployment to the list of deployments, commit, and
+ * cleanup.  By default, all other deployments for the given @osname
+ * except the merge deployment and the booted deployment will be
+ * garbage collected.
+ *
+ * If %OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN is
+ * specified, then all current deployments will be kept.
+ */
+gboolean
+ostree_sysroot_simple_write_deployment (OstreeSysroot      *sysroot,
+                                        const char         *osname,
+                                        OstreeDeployment   *new_deployment,
+                                        OstreeDeployment   *merge_deployment,
+                                        OstreeSysrootSimpleWriteDeploymentFlags flags,
+                                        GCancellable       *cancellable,
+                                        GError            **error)
+{
+  gboolean ret = FALSE;
+  guint i;
+  OstreeDeployment *booted_deployment = NULL;
+  gs_unref_ptrarray GPtrArray *deployments = NULL;
+  gs_unref_ptrarray GPtrArray *new_deployments = g_ptr_array_new_with_free_func (g_object_unref);
+  gboolean retain = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN) > 0;
+
+  deployments = ostree_sysroot_get_deployments (sysroot);
+  booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
+
+  if (osname == NULL && booted_deployment)
+    osname = ostree_deployment_get_osname (booted_deployment);
+
+  g_ptr_array_add (new_deployments, g_object_ref (new_deployment));
+
+  for (i = 0; i < deployments->len; i++)
+    {
+      OstreeDeployment *deployment = deployments->pdata[i];
+      
+      /* Keep deployments with different osnames, as well as the
+       * booted and merge deployments
+       */
+      if (retain ||
+          (osname != NULL &&
+           strcmp (ostree_deployment_get_osname (deployment), osname) != 0) ||
+          ostree_deployment_equal (deployment, booted_deployment) ||
+          ostree_deployment_equal (deployment, merge_deployment))
+        {
+          g_ptr_array_add (new_deployments, g_object_ref (deployment));
+        }
+    }
+
+  if (!ostree_sysroot_write_deployments (sysroot, new_deployments, cancellable, error))
+    goto out;
+
+  if (!ostree_sysroot_cleanup (sysroot, cancellable, error))
+    goto out;
+
+  ret = TRUE;
+ out:
+  return ret;
+}
+
index ec4513baebb01a6c69c1a6209a54828fbf79e16a..7bfda2c81e47cb387ba0e4026b7ca45b06bc56fe 100644 (file)
@@ -94,5 +94,18 @@ OstreeDeployment *ostree_sysroot_get_merge_deployment (OstreeSysroot     *self,
 GKeyFile *ostree_sysroot_origin_new_from_refspec (OstreeSysroot      *self,
                                                   const char         *refspec);
 
+typedef enum {
+  OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NONE = 0,
+  OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN = (1 << 0)
+} OstreeSysrootSimpleWriteDeploymentFlags;
+
+gboolean ostree_sysroot_simple_write_deployment (OstreeSysroot      *sysroot,
+                                                 const char         *osname,
+                                                 OstreeDeployment   *new_deployment,
+                                                 OstreeDeployment   *merge_deployment,
+                                                 OstreeSysrootSimpleWriteDeploymentFlags flags,
+                                                 GCancellable       *cancellable,
+                                                 GError            **error);
+
 G_END_DECLS
 
index e2e0e1ede28a684059603ae6a5be898580b77aee..b99497fe0dbdf1122ea857106d250ea8890db8d9 100644 (file)
@@ -174,9 +174,10 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeSysroot *sysroot, GCancell
       goto out;
   }
 
-  if (!ot_admin_complete_deploy_one (sysroot, opt_osname,
-                                     new_deployment, merge_deployment, opt_retain,
-                                     cancellable, error))
+  if (!ostree_sysroot_simple_write_deployment (sysroot, opt_osname,
+                                               new_deployment, merge_deployment,
+                                               opt_retain ? OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN : 0,
+                                               cancellable, error))
     goto out;
 
   ret = TRUE;
index 87f5893b36ec061ee9704f34ad28fb6d8378e793..1edd7f5d4f83c4f1b0373c0d9168020ea1e4c56d 100644 (file)
@@ -148,9 +148,11 @@ ot_admin_builtin_switch (int argc, char **argv, OstreeSysroot *sysroot, GCancell
                                        cancellable, error))
         goto out;
 
-      if (!ot_admin_complete_deploy_one (sysroot, opt_osname,
-                                         new_deployment, merge_deployment, FALSE,
-                                         cancellable, error))
+      if (!ostree_sysroot_simple_write_deployment (sysroot, opt_osname,
+                                                   new_deployment,
+                                                   merge_deployment,
+                                                   0,
+                                                   cancellable, error))
         goto out;
 
       if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
index 16a4073d2b6a97422e5a05def6765642e06b909c..badaf2e27e83184653b1482466334250edfd5ee0 100644 (file)
@@ -176,9 +176,11 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
                                        cancellable, error))
         goto out;
 
-      if (!ot_admin_complete_deploy_one (sysroot, opt_osname,
-                                         new_deployment, merge_deployment, FALSE,
-                                         cancellable, error))
+      if (!ostree_sysroot_simple_write_deployment (sysroot, opt_osname,
+                                                   new_deployment,
+                                                   merge_deployment,
+                                                   0,
+                                                   cancellable, error))
         goto out;
 
       if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
index 6b54fb2c168524967133dc648387531796559d6c..198f3e48d537800f72a9c074a5bb3dc17face878 100644 (file)
@@ -49,64 +49,6 @@ ot_admin_require_booted_deployment_or_osname (OstreeSysroot       *sysroot,
   return ret;
 }
 
-gboolean
-ot_admin_complete_deploy_one (OstreeSysroot      *sysroot,
-                              const char         *osname,
-                              OstreeDeployment   *new_deployment,
-                              OstreeDeployment   *merge_deployment,
-                              gboolean            opt_retain,
-                              GCancellable       *cancellable,
-                              GError            **error)
-{
-  gboolean ret = FALSE;
-  guint i;
-  OstreeDeployment *booted_deployment = NULL;
-  gs_unref_ptrarray GPtrArray *deployments = NULL;
-  gs_unref_ptrarray GPtrArray *new_deployments = g_ptr_array_new_with_free_func (g_object_unref);
-
-  deployments = ostree_sysroot_get_deployments (sysroot);
-  booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
-
-  if (osname == NULL && booted_deployment)
-    osname = ostree_deployment_get_osname (booted_deployment);
-
-  g_ptr_array_add (new_deployments, g_object_ref (new_deployment));
-
-  for (i = 0; i < deployments->len; i++)
-    {
-      OstreeDeployment *deployment = deployments->pdata[i];
-      
-      /* Keep deployments with different osnames, as well as the
-       * booted and merge deployments
-       */
-      if (opt_retain ||
-          (osname != NULL &&
-           strcmp (ostree_deployment_get_osname (deployment), osname) != 0) ||
-          ostree_deployment_equal (deployment, booted_deployment) ||
-          ostree_deployment_equal (deployment, merge_deployment))
-        {
-          g_ptr_array_add (new_deployments, g_object_ref (deployment));
-        }
-      else
-        {
-          g_print ("ostadmin: Will delete deployment osname=%s %s.%u\n",
-                   ostree_deployment_get_osname (deployment),
-                   ostree_deployment_get_csum (deployment),
-                   ostree_deployment_get_deployserial (deployment));
-        }
-    }
-
-  if (!ostree_sysroot_write_deployments (sysroot, new_deployments, cancellable, error))
-    goto out;
-
-  if (!ostree_sysroot_cleanup (sysroot, cancellable, error))
-    goto out;
-
-  ret = TRUE;
- out:
-  return ret;
-}
-
 gboolean
 ot_admin_deploy_prepare (OstreeSysroot      *sysroot,
                          const char         *osname,
index d42c974cb70e0857a803327df033803b5112cf82..8d903713a298827d5212d6ed519ec97a749fb5df 100644 (file)
@@ -43,14 +43,5 @@ ot_admin_deploy_prepare (OstreeSysroot      *sysroot,
                          GCancellable        *cancellable,
                          GError             **error);
 
-gboolean
-ot_admin_complete_deploy_one (OstreeSysroot      *sysroot,
-                              const char         *osname,
-                              OstreeDeployment   *new_deployment,
-                              OstreeDeployment   *merge_deployment,
-                              gboolean            opt_retain,
-                              GCancellable        *cancellable,
-                              GError             **error);
-
 G_END_DECLS